class Solution {
public:
    bool isValid(string s) {
        int top=0;
        string array;
        array.resize(s.size()+1);
        for (int i = 0; i < s.size(); i++)
        {
            if (array[top] == '('&&s[i]==')'|| array[top] == '[' && s[i] == ']'|| array[top] == '{' && s[i] == '}')
            {
                top--;
            }
            else {
                top++;
                array[top]=s[i];
            }
        }
        if (top==0)
        {
            return true;
        }
        return false;
    }
};